/******************************************************************************
* File description: OpenFileLocateFileUpload.qml
* Function: 打开-本地文件：上传文件
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-08-31
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14

Item {
    id: root

    /* property 定义开始 */

    // 私有
    // TabBar标题
    property var _barTitleList: ["本地设备", "USB存储", "网络存储"]
    // 是否为网络存储
    property bool isWeb: false
    // 当前路径
    property string _currentPath: "本地设备"

    // 信号
    signal currentIndexChanged(int index);
    signal cancel()
    signal webAdd()

    /* property 定义结束 */

    // tabbar
    TabBar {
        id: tabBar
        width: implicitWidth
        height: 20
        anchors {
            top: parent.top
            left: parent.left
            topMargin: 20
            leftMargin: 25
        }
        background: Rectangle{color: "transparent"}
        spacing: 24

        Repeater {
            model: root._barTitleList

            TabButton {
                implicitHeight: parent.height

                // 文字
                contentItem: Label{
                    id: text
                    anchors {
                        fill: parent
                    }
                    bottomPadding: 2
                    font {
                        pixelSize: 16
                    }
                    verticalAlignment: Text.AlignVCenter
                    horizontalAlignment: Text.AlignHCenter
                    color: "#FF222222"
                    text: qsTr(modelData)
                }

                // 背景
                background: Rectangle{
                    color: "transparent"

                    // 绘制下边框
                    Canvas {
                        anchors.fill: parent
                        visible: index === tabBar.currentIndex
                        antialiasing: true
                        onPaint: {
                            var ctx = getContext("2d")
                            ctx.strokeStyle = "#FF2F42CD"
                            ctx.lineWidth = 6
                            ctx.beginPath()
                            ctx.moveTo(0, height)
                            ctx.lineTo(width, height)
                            ctx.stroke()
                        }
                    }
                }

                onClicked: {
                    tabBar.currentIndexChanged(index)
                    root._currentPath = root._barTitleList[index]
                    root.isWeb = index === 2
                }
            }
        }
    }

    // 主内容
    StackLayout {
        id: mainContentLayout
        anchors {
            fill: parent
            topMargin: tabBar.height + 36
        }

        Item {
            id: locateFile
            Layout.fillWidth: true
            Layout.fillHeight: true

            ColumnLayout {
                id: locateFileLayout
                anchors.fill: parent

                // 主内容
                Item {
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Layout.leftMargin: 24
                    Layout.rightMargin: 24
                    Layout.topMargin: 15

                    ColumnLayout {
                        anchors.fill: parent
                        spacing: 30

                        // 当前路径
                        Item {
                            Layout.fillWidth: true
                            Layout.preferredHeight: 40

                            RowLayout {
                                anchors.fill: parent

                                Label {
                                    font.pixelSize: 16
                                    color: "#FF222222"
                                    text: `当前路径：${root._currentPath}\\`
                                }

                                CustomHorSpacerItem {}

                                // 添加
                                PureButton {
                                    id: webAddBtn
                                    visible: root.isWeb
                                    Layout.preferredWidth: 120
                                    Layout.preferredHeight: 40
                                    pureBtnColor: "#FF2F42CD"
                                    pureHoveredColor: "#FF2F42CD"
                                    pureLabelColor: "#FFFFFFFF"
                                    pureFontHoveredColor: "#FFFFFFFF"
                                    pureBtnBorderColor: "transparent"
                                    pureText: "添加"
                                    // 关闭过渡效果
                                    isTransition: false
                                    onReleased: {
                                        root.webAdd()
                                    }
                                }
                            }
                        }

                        // 所有文件
                        Flickable {
                            Layout.fillWidth: true
                            Layout.fillHeight: true
                            clip: true
                            contentHeight: filesLayout.height

                            ColumnLayout {
                                id: filesLayout
                                spacing: 30

                                Repeater {
                                    model: 30

                                    Item {
                                        Layout.fillWidth: true
                                        Layout.preferredHeight: 30

                                        // 图片
                                        Rectangle {
                                            id: imgItem
                                            width: 30
                                            height: 30
                                            color: "#80FF0000"
                                        }

                                        Label {
                                            height: parent.height
                                            anchors {
                                                left: imgItem.right
                                                leftMargin: 9
                                            }
                                            verticalAlignment: Text.AlignVCenter
                                            font.pixelSize: 16
                                            color: "#FF222222"
                                            clip: true
                                            elide: Text.ElideRight
                                            text: String(index) + " " + root._currentPath
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // 底部按钮部分
                Item {
                    id: bottomBtnsCon
                    Layout.fillWidth: true
                    Layout.preferredHeight: 40
                    Layout.bottomMargin: 40
                    Layout.topMargin: 40

                    RowLayout {
                        anchors.fill: parent

                        CustomHorSpacerItem {}

                        // 取消
                        PureButton {
                            id: cancelbtn
                            Layout.preferredWidth: 120
                            Layout.preferredHeight: 40
                            pureText: "取消"
                            // 关闭过渡效果
                            isTransition: false

                            onReleased: {
                                root.cancel()
                            }
                        }

                        // 上传
                        PureButton {
                            id: uploadBtn
                            Layout.preferredWidth: 120
                            Layout.preferredHeight: 40
                            pureBtnColor: "#FF2F42CD"
                            pureHoveredColor: "#FF2F42CD"
                            pureLabelColor: "#FFFFFFFF"
                            pureFontHoveredColor: "#FFFFFFFF"
                            pureBtnBorderColor: "transparent"
                            pureText: "上传"
                            // 关闭过渡效果
                            isTransition: false
                        }

                        CustomHorSpacerItem {}
                    }
                }
            }

        }

    }
}
